<?php
require_once 'cc.php';
$array = array(
    'code' => 0,
    'data' => false,
    'msg' => '缺少参数',
);

if (!isset($_REQUEST['username']) || !isset($_REQUEST['password'])) {
    die(json_encode($array));
}

$name = $_REQUEST['username'];
$pwd = $_REQUEST['password'];
$phone = $_REQUEST['phone'];
$sql = "SELECT * FROM shop where 'username' = '$username'";
$result = mysqli_query($conn, $sql);
$data = mysqli_fetch_assoc($result);
$array = array(
    'code' => 0,
    'data' => false,
    'msg' => '用户名已存在',
);
// var_dump($data);
if (!$data) {
    // die('1');
    $sql = "INSERT INTO shop (username, password ,phone) VALUES ('$name','$pwd','$phone')";
    mysqli_query($conn, $sql);
    $res = mysqli_affected_rows($conn);

//$rows = mysqli_affected_rows($conn);

    if ($res>0) {
        // 插入成功
        // code是后端自定义的，我们这里定义1成功，0失败
        echo json_encode(array(
            "code" => 1,
            "msg" => "注册成功",
        ));
    } else {
        echo json_encode(array(
            "code" => 0,
            "msg" => "网络错误，请重试",
        ));
    }

}
